<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登陆</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
</head>
<body>
    <form action="" id="login-form">
        <input type="hidden" name="op" value="doLogin">
        <p>登录名: <input type="text" name="username"></p>
        <p>密码： <input type="password" name="userpass"></p>
        <p> <input type="button" value="登陆" id="btn"></p>
    </form>
    <script>
        $(document).ready(function(){
            $("#btn").click(function(){
                $.post("http://localhost:8080/study/userlogin",$("#login-form").serialize(),function(res){
                    if(res.code==200){
                        // 计算半小时以后的时间
                        let date = new Date();
                        date = new Date(date.getTime()+(1000 * 60 * 30));
                        // 将token放入cookie
                        $.cookie("token", res.msg, {path: "/", expiress: date})
                        location.href="index.html";    
                    }else{
                        alert("登陆失败");
                    }
                });
            });
        });
    </script>
</body>
</html>